# Maintainer: Gore Liu <goreliu@126.com>

_realname=jq
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.5
pkgrel=4
pkgdesc="Command-line JSON processor (mingw-w64)"
arch=('any')
url='https://stedolan.github.io/jq/'
license=('MIT')
makedepends=("autoconf" "automake" "bison" "flex" "python2")
depends=("${MINGW_PACKAGE_PREFIX}-oniguruma")
source=("https://github.com/stedolan/${_realname}/releases/download/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.gz"
        no-undefined.patch
        missing-library.patch)
sha256sums=('c4d2bfec6436341113419debf479d833692cc5cdab7eb0326b5a4d4fbe9f493c'
            'e4b6f5eb5bfeda43564bcede307eac36cf26dbd3437eef45b51b2db617a525b5'
            'cbc4365d5ea514a318568582693e1883249473c64b79609007fe3c565b2b81ed')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/no-undefined.patch
  patch -p1 -i ${srcdir}/missing-library.patch
  
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

check() {
    cd "${srcdir}"/build-${CARCH}
  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
